package com.learn.chapter2.main;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.learn.chapter2.mapper.RoleMapper;
import com.learn.chapter2.po.Role;
import com.learn.chapter2.util.SqlSessionFactoryUtil;

public class TestMain {

	public static void main(String[] args) throws IOException {
		SqlSession sqlSession = null;
		try {
			sqlSession = SqlSessionFactoryUtil.openSqlSession();
			RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);
			Role role = new Role();
			role.setRoleName("用户名");
			role.setNote("testNote");
			roleMapper.insertRole(role);
			roleMapper.deleteRole(2L);
			List<Role> list = roleMapper.selectAll();
			for (Role tmp: list) {
				System.out.println(tmp.getId());
			}
			sqlSession.commit();
		} catch (Exception e) {
			System.err.println(e.getMessage());
			sqlSession.rollback();
		} finally {
			if (sqlSession != null) {
				sqlSession.close();
			}
		}
	}

}
